/**
 * User: Ngannv
 * Date: 9/17/11
 * Email : ngankt2@gmail.com
 */
var doc = document;
function getFileExtension(file_name) {
    if (!file_name || file_name == '') {
        return "";
    }
    var dot = file_name.lastIndexOf(".");
    if (dot == -1) return "";
    var extension = file_name.substr(dot, file_name.length);
    return extension;
}
/**
 * @By ngannv 18.09.2011
 * @param file_name =abc.jpg
 * @param list_extension =['jpg','jpeg','gif','png'];
 * @return bool
 */
function checkFileExtension(file_name, list_extension) {
    if (!file_name) return false;
    var dot = file_name.split(".");
    var file_ext = dot[dot.length - 1];
    for (i in list_extension) {
        if (file_ext.toLowerCase() == list_extension[i].toLowerCase()) {
            return true;
        }
    }
    return false;
}
/**
 * @By ngannv
 * @param obj=input type="file"
 * @param img_tag_id
 */
function displayImage(obj, img_tag_id) {
    var val = jQuery('#' + obj.id).attr('value').toLowerCase();
    var extension_allow = ['jpg','png','jpeg','gif'];
    if (checkFileExtension(val, extension_allow)) {
        if (obj.files[0] && obj.files) {
            jQuery('#'+img_tag_id).attr('src', obj.files[0].getAsDataURL());
        }
    } else {
        alert("Bạn vui lòng chọn file hình ảnh dạng .jpg , .png , .gif, .jpeg");
        return false;
    }
    //alert(print_r(obj.files[0].getAsDataURL()));
}